package threadings;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: yyx
 * Date: 2024-01-17
 * Time: 12:28
 */
public class ThreadDemo6 {
    public static boolean isQuit = false;

    public static void main(String[] args) {
//        boolean isQuit = false;

        Thread t = new Thread(()->{
           while (!isQuit){
               System.out.println("hello t ");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
            System.out.println("线程中断");
        });

        t.start();

        try {
            Thread.sleep(4000);//主线程休眠4s,然后修改成员变量isQuit的值
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isQuit = true;

    }
}
